import { dialog, ipcMain, shell } from 'electron';

/**
 * 返回文件的绝对路径
 * @param  {boolena} isFile
 * @return  filePaths
 * @example getFilePath();
 */
export function getFilePath() {
    ipcMain.handle("getFilePath", async (event,isFile) => {
        let filePaths:any;
        if(isFile){
            filePaths = (await dialog.showOpenDialog({ properties: ['openFile'] })).filePaths;
        }else{
            filePaths = (await dialog.showOpenDialog({ properties: ["openDirectory"] })).filePaths;
        }
        return filePaths.length > 0 ? filePaths[0] : null;
    })
}

export function openFile(){
    ipcMain.handle("openFile",async (event,url)=>{
        shell.openPath(url)
    })
}